<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>工厂模式-ES6</title>
</head>
<body>
    
</body>
<script>
    class Restaurant{
        static getMenu(menu){
            switch(menu){
                case '鱼香肉丝':return new YuXiangRouSi();
                case '宫保鸡丁':return new GongBaoJiDing();
                default:throw new Error('本店没有这个菜')
            }
        }
    }

    class YuXiangRouSi{
        constructor(){
            this.type='鱼香肉丝'
        }
        eat(){
            console.log(this.type+'真香')
        }
    }

    class GongBaoJiDing{
        constructor(){
            this.type='宫保鸡丁'
        }
        eat(){
            console.log(this.type+'让我想起了老家')
        }
    }

    const dash1=Restaurant.getMenu('鱼香肉丝')
    dash1.eat()
    const dash2=Restaurant.getMenu('红烧排骨')
    dash2.eat()
    //Error:本店没有这个菜
</script>
</html>